package cn.wolfcode.cms.web.controller;

import cn.wolfcode.cms.annotation.PermissionName;
import cn.wolfcode.cms.domain.Recharge;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IRechargeService;
import cn.wolfcode.cms.util.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//充值
@Controller
@RequestMapping("recharge")
public class RechargeController {

    @Autowired
    private IRechargeService rechargeService;

    @RequiresPermissions("recharge:index")
    @PermissionName("充值首页")
    @RequestMapping("")
    public String index() {
        rechargeService.list();
        return "recharge/pay";
    }

    //充值信息列表/带分页
    @RequiresPermissions("recharge:list")
    @PermissionName("充值列表")
    @RequestMapping("list")
    @ResponseBody
    public Object list(QueryObject qo) {
        return rechargeService.query(qo);
    }


    //所有充值信息数据/无分页
    @RequestMapping("listData")
    @ResponseBody
    public Object listData() {
        return rechargeService.list();
    }


    //充值添加
    @RequiresPermissions("recharge:save")
    @PermissionName("充值添加")
    @RequestMapping("save")
    @ResponseBody
    public Object save(Recharge entity) {
        JSONResult result = new JSONResult();
        try {
            rechargeService.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("添加失败");
        }
        return result;
    }

}
